<template>
  <div id="cooperate">
    <!-- 头部区域 -->
    <topheader></topheader>
    <!-- 内容区域 -->
    <div class="cooperatecontent">
      <div class="cooperate-title">
        <h2>欢迎使用万骏驾考-企业版</h2>
        <p>请确保信息真实有效，不得冒用他人身份或驾校资质，一经发现将承担所有法律责任，并永久撤销该注册人平台使用资格。</p>
      </div>
      <div class="cooperate-form">
        <div class="inner-form">
          <el-form
            label-position="left"
            ref="enter"
            :model="enterform"
            :rules="enterformru"
            size="medium"
            label-width="100px"
          >
            <el-form-item label="选择城市" prop="city">
              <el-cascader
                size="large"
                placeholder="请选择城市"
                :options="options"
                v-model="enterform.city"
                :show-all-levels="true"
                @change='changeArea'
                :style="{ width: '100%' }"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="类型">
              <div class="typebox">
                <img src="https://qiye.wanjunjiakao.com/norm/icon-1.svg" alt="" />
                <div class="r-info">
                   <p>总校/直营</p>
                <span>
                  会展示到万骏驾考中，入驻需认证，用于营销、招生、管理
                </span>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="驾校名称" prop="short_title">
              <el-input
                size="large"
                v-model="enterform.short_title"
                placeholder="请输入驾校名称,如:万骏驾校"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
            <el-form-item label="企业名称" prop="title">
              <el-input
                size="large"
                v-model="enterform.title"
                placeholder="需与营业执照名称一致"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="leader_man">
              <el-input
                size="large"
                v-model="enterform.leader_man"
                placeholder="请输入姓名"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="leader_tel">
              <el-input
               @input="changephone"
                size="large"
                v-model="enterform.leader_tel"
                placeholder="此手机号用于万骏驾考·企业版后台登录"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="sms_code">
              <div class="phoneCodearea">
                <el-input
                  v-model="enterform.sms_code"
                  size="large"
                  :placeholder="placeholderTetx"
                  class="codeinput"
                ></el-input>
                <!-- <span class="showCode" v-if="isshowSendCode">请输入编号为{{enterform.sms_sign}}的验证码</span> -->
                <el-button
                  type="primary"
                  size="large"
                  :disabled="isdisable"
                  @click="sendCode"
                >
                  {{ sendCodetext }}{{ senCodetime }}
                </el-button>
              </div>
            </el-form-item>
            <div class="subbtn">
              <el-button
                type="primary"
                class="subelbtn"
                size="large"
                @click="submitForm"
              >
                提交
              </el-button>
            </div>
            <div class="formfooter">
              <span>
                点击提交即视为同意
                <a href="https://qiye.wanjunjiakao.com/norm/privacy.html" target="_blank">《万骏驾考企业版服务协议》</a>
              </span>
            </div>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//头部组件
import topheader from './component/topheader'
import { isPhone } from '@/utils/validate'
//api
import { getArea,getCode} from '@/api/common'
// api
import {cooperate} from '@/api/cooperate'
export default {
  data() {
    return {
      placeholderTetx:'请输入验证码',
      //发送验证码成功显示 验证码提示
      // isshowSendCode:false,
      //验证码计时器
      secodeTimer: null,
      //是否禁用发送验证码
      isdisable: true,
      //验证码倒计时
      senCodetime: '',
      sendCodetext: '发送验证码',
      enterform: {
        city: '',
        type: '1',
        title: '',
        short_title: '',
        leader_man: '',
        leader_tel:'',
        sms_code:'',
        //sms短信验证
      sms_sign:''
      },
      enterformru: {
        city: [
          {
            required: true,
            message: '请选择城市',
            trigger: 'change',
          },
        ],
        short_title: [
          {
            required: true,
            message: '请输入驾校名称',
            trigger: 'blur',
          },
        ],
        title: [
          {
            required: true,
            message: '请输入企业名称',
            trigger: 'blur',
          },
        ],
        leader_man: [
          {
            required: true,
            message: '请输入姓名',
            trigger: 'blur',
          },
        ],
        leader_tel: [
          {
            required: true,
            message: '请输入手机号',
            trigger: 'blur',
          },
        ],
        sms_code:[
           {
            required: true,
            message: `请输入验证码`,
            trigger: 'blur',
          },
        ]
      },
      //地区选项
      options: [],
    }
  },
  components: {
    topheader,
  },
  methods: {

    submitForm() {
      this.$refs['enter'].validate(async (valid) => {
        if (!valid) return
        // TODO 提交表单
        this.$store
              .dispatch('user/Enterlogin', this.enterform)
              .then((res) => {
                

                const routerPath =
                  this.redirect === '/404' || this.redirect === '/401'
                    ? '/'
                    : this.redirect
                this.$router.push(routerPath).catch(() => {})
              })
              .catch(() => {
               
              })
      })
    },
    //发送验证码
    async sendCode() {
      let params = {
        tel:this.enterform.leader_tel,
        type:'register'
      }
      let data = await getCode(params)
      if(data.code=='0001') return
      if(data.code=='0000'){
      
        this.enterform.sms_sign = data.data.smsSign
        //显示提示验证码
        // this.isshowSendCode = true
        this.placeholderTetx = '请输入编号为'+this.enterform.sms_sign+'验证码'
         clearInterval(this.secodeTimer)
      this.sendCodetext = '已发送'
      //验证码计时器60秒
      this.senCodetime = 60
      this.isdisable = true
      this.secodeTimer = setInterval(() => {
        if (this.senCodetime == 0) {
          this.senCodetime = ''
          this.sendCodetext = '发送验证码'
           this.placeholderTetx = '请输入验证码'
          this.isdisable = false
          return
        } else {
          this.senCodetime--
        }
      }, 1000)
      }
     
    },
    //监听手机号输入事件
    changephone(val) {
      let result = isPhone(val)
      //手机号正确 就取消禁用
      if (result) {
        this.isdisable = false
      }
    },
    //获取地区选项
    async getAreaOption(){
      let data = await getArea();
      this.options = data.data
    },
    //选择地区触发
    changeArea(val){
      this.enterform.city = val[val.length-1]
    }
  },
  mounted(){
    //获取社保地区
    this.getAreaOption()
  }
}
</script>

<style scoped lang='scss'>
#cooperate {
  padding-top: 69px;
  width: 100%;
  height: 100%;
  background-color: #f3f5f8;
  .cooperatecontent {
    .cooperate-title {
      text-align: center;
      h2 {
        margin-top: 40px;
        font-weight: bold;
        font-size: 29px;
        color: #232841;
      }
      p {
        font-size: 14px;
        color: #ff4d4f;
        line-height: 28px;
      }
    }
    .cooperate-form {
      box-shadow: 0 4px 30px 0 rgba(99,121,204,.1);
      border-radius: 5px;
      width: 1000px;
      height: 900px;
      background-color: #fff;
      margin: 0 auto;
      margin-bottom:60px;
      .inner-form {
        width: 497px;
        margin: 0 auto;
        padding-top: 40px;
      }
    }
  }
}
.phoneCodearea {
  display: flex;
  .codeinput {
    margin-right: 10px;
  }
}
.subbtn {
  display: flex;
  justify-content: center;
  margin-bottom: 21px;
  margin-top: 43px;
  .subelbtn {
    width: 198px;
    height: 40px;
  }
}
.formfooter {
  margin-top: 30px;
  display: flex;
  justify-content: center;
  span {
    display: flex;
    align-items: center;
    font-size: 12px;
    a {
      font-size: 12px;
    }
  }
}
.typebox {
  display: flex;
  align-items: center;
  padding: 0 15px;
  border: 1px solid #5288ff;
  background: #f8fbff;
  box-sizing: border-box;
  padding-bottom: 5px;
  padding-top: 5px;
  border-radius: 5px;
  img {
    width: 48px;
    // height: 65px;
    margin-right: 5px;
  }
  p {
    font-size: 16px;
    margin: 0;
    padding: 0;
  }
  span {
    display: block;
    font-size: 12px;
    display: block;
    line-height: 20px;
    text-align: justify;
    color: #999;
    // margin-top: 5px;
    position: relative;
    top: -5px;
  }
}
</style>